import 'package:flutter/material.dart';
import 'package:ls_work/a_training/model/train_entity.dart';
import 'package:ls_work/net/net.dart';
import 'package:ls_work/res/gaps.dart';
import 'package:ls_work/res/styles.dart';
import 'package:ls_work/widgets/load_image.dart';
import 'package:flutter_html/flutter_html.dart';

class TrainingDetailPage extends StatefulWidget {
  final TrainInfo? info;
  TrainingDetailPage({Key? key, this.info});
  @override
  _TrainingDetailPageState createState() => _TrainingDetailPageState();
}

class _TrainingDetailPageState extends State<TrainingDetailPage> {
  // TrainDtailInfo info;
  // String _titile = '';
  // String _content = '';
  // String _time = '';
  // String _pic = '';

  @override
  void initState() {
    // WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
    //   _fectData();
    // });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('详情'),
        elevation: 0.5,
      ),
      body: SingleChildScrollView(
        child: Container(
          padding: EdgeInsets.all(12),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Text(
                '${widget.info?.name ?? ''}',
                style: TextStyles.textBoldDark18,
              ),
              Gaps.vGap5,
              Text(
                '${widget.info?.createdDate ?? ''}',
                style: TextStyles.textGray12,
              ),
              Gaps.vGap10,
              LoadImage(
                '${HttpApi.imageDownLoadUrl}${widget.info?.attachId}',
                width: double.infinity,
                height: 150,
              ),
              Gaps.vGap10,
              Html(
                data: '${widget.info?.detail??""}',
              ),
            ],
          ),
        ),
      ),
    );
  }

  // _fectData() {
  //   SVProgressHUD page = SVProgressHUD(context);
  //   page.showProgress();
  //   var map = {'id': widget.id};
  //   HttpUtil.instance
  //       .getDio()
  //       .post(HttpApi.staffTrainingDetail, data: map)
  //       .then((r) {
  //     ///
  //     page.closeProgress();
  //     if (r.statusCode == 200) {
  //       Map<String, dynamic> map = json.decode(r.toString());
  //       if (map["code"].toString() == "0") {
  //
  //         if (map['data'] != null) {
  //           TrainDtailInfo model = TrainDtailInfo.fromJson(map['data']);

  //           setState(() {
  //             info = model;

  //             _titile = model.title != null ? model.title : '';
  //             _content = model.content != null ? model.content : '';
  //             _time = model.createdDate != null ? model.createdDate : '';
  //             _pic = model.mainPicPath != null ? model.mainPicPath : '';
  //           });
  //         } else {
  //           Toast.show(map["msg"]);
  //         }
  //       }
  //     } else {
  //       Toast.show(r.statusCode.toString());
  //     }
  //   }).catchError((e) {
  //     page.closeProgress();
  //     print(e.toString());
  //     Toast.show(getErrorMessage(e));
  //   });
  // }
}
